package com.example.haojiutao.controller.user;

import com.example.haojiutao.common.Result;
import com.example.haojiutao.model.domain.GoodsType;
import com.example.haojiutao.service.GoodsTypeService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 商品种类控制层
 * @Author: ma_lihong
 * @CreateTime: 2024/1/29 14:03
 */
@Slf4j
@RestController
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    /*
     * @Description:根据id查询
     * @Author: ma_lihong
     * @CreateTime: 2024/1/29  14:03
     * @param: goodsType
     * @return: com.example.haojiutao.common.Result
     */
    @GetMapping("/user/goodstype/{typeId}")
    public Result selectById(@PathVariable Integer typeId){
        log.info("查看单个商品");
        GoodsType goodsType = new GoodsType();
        GoodsType goodsType1 = goodsTypeService.selectById(typeId);
        return Result.success("查询成功！",goodsType);
    }
    /*
     * @Description: 列表查询
     * @Author: ma_lihong
     * @CreateTime: 2024/1/29  15:06
     * @param: gt
     * @return: com.example.haojiutao.common.Result
     */
    @CrossOrigin(origins = {"http://localhost:5173"}, allowCredentials = "true")
    @GetMapping("/user/goodstype/list")
    public Result selectListByUser(GoodsType gt){
        log.info("列表查询");

        List<GoodsType> types = goodsTypeService.selectListByUser(gt);
        System.out.println("================"+types);
        PageInfo<GoodsType> pageInfo = new PageInfo<>(types);
        return Result.success("查询成功",pageInfo);

    }

}